using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using TinyERP.Framework;
using TinyERP.Framework.Controls;
using TinyERP.Framework.Validation;
using TinyERP.ERP.Business;
using TinyERP.ERP.DTO;
using log4net;
namespace TinyERP.View
{
    public class CustomerEditInfoForm : BasicEditInfoDialog
    {
        private ILog logger = LogManager.GetLogger(typeof(CustomerEditInfoForm));
		private CustomerDTO customer;
		private KLabel lblFirstName;
		private TextBox txtFirstName;
		private KLabel lblLastName;
		private TextBox txtLastName;
		private KLabel lblTitle;
		private TextBox txtTitle;
		private KLabel lblDescription;
		private TextBox txtDescription;
        private KLabel lblPhoneNumber;
		private KLabel lblWebSite;
		private TextBox txtWebSite;
        private KLabel lblIM;
		private KLabel lblFax;
		private TextBox txtFax;
		private KLabel lblCustomerAddressList;

        private KLabel lblCustomerType;
        private ComponentFactory.Krypton.Toolkit.KryptonComboBox cboCustomerType;
        private TextBox txtEmail;
        private KLabel lblEmail;
        private KLabel lblBirthdate;
        private DateTextBox txtBirthDate;
        
        private DataGridViewTextBoxColumn colPhoneNumber;
        private DataGridViewTextBoxColumn colPhoneType;
        private DataGridViewComboBoxColumn colPhoneNumberType;
        private DataGridViewCheckBoxColumn colIsPrimaryPhoneNumber;

        private RemoveIconButton btnRemovePhone;
        private RemoveIconButton btnRemoveAddress;
        private AddIconButton btnAddAddress;
        private RemoveIconButton btnRemoveIM;
        private AddIconButton btnAddIM;
        private DataGridViewTextBoxColumn colStreetAddress;
        private DataGridViewTextBoxColumn colCity;
        private DataGridViewTextBoxColumn colCountry;
        private ComponentFactory.Krypton.Toolkit.KryptonDataGridViewCheckBoxColumn colIsMainAddress;
        private AddIconButton btnAddPhone;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
        private DataGridViewComboBoxColumn dataGridViewComboBoxColumn1;
        private DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1;
        TinyERP.Framework.Controls.CustomDataGridView gridAddress;
        TinyERP.Framework.Controls.CustomDataGridView gridPhoneNumber;
        TinyERP.Framework.Controls.CustomDataGridView gridIM;

		public CustomerDTO Customer
		{
			get 
			{
				return customer;
			}
			set 
			{
				customer = value;
                LoadEntityInfo();
			}
		}
		public ICustomerService CustomerService 
		{
			get
			{
				return (ICustomerService) ServiceLocator.GetService("CustomerServiceProxy");
			}
		}
		
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle11 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
            
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle12 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
            
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CustomerEditInfoForm));
            this.colStreetAddress = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colCity = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colCountry = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colIsMainAddress = new ComponentFactory.Krypton.Toolkit.KryptonDataGridViewCheckBoxColumn();
            this.colPhoneNumber = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colPhoneType = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colPhoneNumberType = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.colIsPrimaryPhoneNumber = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            this.lblFirstName = new TinyERP.Framework.Controls.KLabel();
            this.txtFirstName = new System.Windows.Forms.TextBox();
            this.lblLastName = new TinyERP.Framework.Controls.KLabel();
            this.txtLastName = new System.Windows.Forms.TextBox();
            this.lblTitle = new TinyERP.Framework.Controls.KLabel();
            this.txtTitle = new System.Windows.Forms.TextBox();
            this.lblDescription = new TinyERP.Framework.Controls.KLabel();
            this.txtDescription = new System.Windows.Forms.TextBox();
            this.lblPhoneNumber = new TinyERP.Framework.Controls.KLabel();
            this.lblWebSite = new TinyERP.Framework.Controls.KLabel();
            this.txtWebSite = new System.Windows.Forms.TextBox();
            this.lblIM = new TinyERP.Framework.Controls.KLabel();
            this.lblFax = new TinyERP.Framework.Controls.KLabel();
            this.txtFax = new System.Windows.Forms.TextBox();
            this.lblCustomerAddressList = new TinyERP.Framework.Controls.KLabel();
            this.lblCustomerType = new TinyERP.Framework.Controls.KLabel();
            this.cboCustomerType = new ComponentFactory.Krypton.Toolkit.KryptonComboBox();
            this.lblEmail = new TinyERP.Framework.Controls.KLabel();
            this.txtEmail = new System.Windows.Forms.TextBox();
            this.lblBirthdate = new TinyERP.Framework.Controls.KLabel();
            this.txtBirthDate = new TinyERP.Framework.Controls.DateTextBox();
            this.btnRemovePhone = new TinyERP.Framework.Controls.RemoveIconButton();
            this.btnAddIM = new TinyERP.Framework.Controls.AddIconButton();
            this.btnRemoveIM = new TinyERP.Framework.Controls.RemoveIconButton();
            this.btnAddAddress = new TinyERP.Framework.Controls.AddIconButton();
            this.btnRemoveAddress = new TinyERP.Framework.Controls.RemoveIconButton();
            this.btnAddPhone = new TinyERP.Framework.Controls.AddIconButton();
            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewComboBoxColumn1 = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            gridAddress = new TinyERP.Framework.Controls.CustomDataGridView();
            gridPhoneNumber = new TinyERP.Framework.Controls.CustomDataGridView();
            gridIM = new TinyERP.Framework.Controls.CustomDataGridView();
            this.contentPanel.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.cboCustomerType)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(gridAddress)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(gridPhoneNumber)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(gridIM)).BeginInit();
            this.SuspendLayout();
            // 
            // buttonPanel
            // 
            this.buttonPanel.Location = new System.Drawing.Point(0, 428);
            this.buttonPanel.Size = new System.Drawing.Size(861, 30);
            // 
            // contentPanel
            // 
            this.contentPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.contentPanel.Controls.Add(gridIM);
            this.contentPanel.Controls.Add(this.btnAddPhone);
            this.contentPanel.Controls.Add(this.btnRemoveAddress);
            this.contentPanel.Controls.Add(this.btnAddAddress);
            this.contentPanel.Controls.Add(this.btnRemoveIM);
            this.contentPanel.Controls.Add(this.btnAddIM);
            this.contentPanel.Controls.Add(this.btnRemovePhone);
            this.contentPanel.Controls.Add(this.txtBirthDate);
            this.contentPanel.Controls.Add(this.lblBirthdate);
            this.contentPanel.Controls.Add(this.txtEmail);
            this.contentPanel.Controls.Add(this.lblEmail);
            this.contentPanel.Controls.Add(this.cboCustomerType);
            this.contentPanel.Controls.Add(gridPhoneNumber);
            this.contentPanel.Controls.Add(gridAddress);
            this.contentPanel.Controls.Add(this.lblFirstName);
            this.contentPanel.Controls.Add(this.txtFirstName);
            this.contentPanel.Controls.Add(this.lblLastName);
            this.contentPanel.Controls.Add(this.txtLastName);
            this.contentPanel.Controls.Add(this.lblTitle);
            this.contentPanel.Controls.Add(this.txtTitle);
            this.contentPanel.Controls.Add(this.lblDescription);
            this.contentPanel.Controls.Add(this.txtDescription);
            this.contentPanel.Controls.Add(this.lblPhoneNumber);
            this.contentPanel.Controls.Add(this.lblWebSite);
            this.contentPanel.Controls.Add(this.txtWebSite);
            this.contentPanel.Controls.Add(this.lblIM);
            this.contentPanel.Controls.Add(this.lblFax);
            this.contentPanel.Controls.Add(this.txtFax);
            this.contentPanel.Controls.Add(this.lblCustomerAddressList);
            this.contentPanel.Controls.Add(this.lblCustomerType);
            this.contentPanel.Size = new System.Drawing.Size(861, 428);
            // 
            // colStreetAddress
            // 
            this.colStreetAddress.DataPropertyName = "StreetAddress";
            dataGridViewCellStyle13.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            this.colStreetAddress.DefaultCellStyle = dataGridViewCellStyle13;
            this.colStreetAddress.FillWeight = 284.7716F;
            this.colStreetAddress.HeaderText = "Street address";
            this.colStreetAddress.MaxInputLength = 200;
            this.colStreetAddress.MinimumWidth = 250;
            this.colStreetAddress.Name = "colStreetAddress";
            // 
            // colCity
            // 
            this.colCity.DataPropertyName = "City";
            this.colCity.FillWeight = 7.614212F;
            this.colCity.HeaderText = "City";
            this.colCity.MinimumWidth = 100;
            this.colCity.Name = "colCity";
            // 
            // colCountry
            // 
            this.colCountry.DataPropertyName = "Country";
            this.colCountry.FillWeight = 7.614212F;
            this.colCountry.HeaderText = "Country";
            this.colCountry.MinimumWidth = 100;
            this.colCountry.Name = "colCountry";
            // 
            // colIsMainAddress
            // 
            this.colIsMainAddress.DataPropertyName = "IsMainAddress";
            dataGridViewCellStyle14.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            dataGridViewCellStyle14.NullValue = false;
            this.colIsMainAddress.DefaultCellStyle = dataGridViewCellStyle14;
            this.colIsMainAddress.FalseValue = null;
            this.colIsMainAddress.HeaderText = "IsMainAddress";
            this.colIsMainAddress.IndeterminateValue = null;
            this.colIsMainAddress.Name = "colIsMainAddress";
            this.colIsMainAddress.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.colIsMainAddress.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.colIsMainAddress.TrueValue = null;
            // 
            // colPhoneNumber
            // 
            this.colPhoneNumber.DataPropertyName = "PhoneNumber";
            dataGridViewCellStyle11.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            this.colPhoneNumber.DefaultCellStyle = dataGridViewCellStyle11;
            this.colPhoneNumber.FillWeight = 151.5113F;
            this.colPhoneNumber.HeaderText = "Phone number";
            this.colPhoneNumber.Name = "colPhoneNumber";
            // 
            // colPhoneType
            // 
            this.colPhoneType.DataPropertyName = "Extension";
            this.colPhoneType.FillWeight = 62.77586F;
            this.colPhoneType.HeaderText = "Ext";
            this.colPhoneType.Name = "colPhoneType";
            // 
            // colPhoneNumberType
            // 
            this.colPhoneNumberType.DataPropertyName = "PhoneType";
            this.colPhoneNumberType.FillWeight = 84.19004F;
            this.colPhoneNumberType.HeaderText = "Phone type";
            this.colPhoneNumberType.Items.AddRange(new object[] {
            "Home",
            "Mobile",
            "Business"});
            this.colPhoneNumberType.Name = "colPhoneNumberType";
            // 
            // colIsPrimaryPhoneNumber
            // 
            this.colIsPrimaryPhoneNumber.DataPropertyName = "IsPrimaryPhoneNumber";
            this.colIsPrimaryPhoneNumber.FillWeight = 101.5228F;
            this.colIsPrimaryPhoneNumber.HeaderText = "Primary";
            this.colIsPrimaryPhoneNumber.Name = "colIsPrimaryPhoneNumber";
            // 
            // lblFirstName
            // 
            this.lblFirstName.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblFirstName.Location = new System.Drawing.Point(9, 16);
            this.lblFirstName.Name = "lblFirstName";
            this.lblFirstName.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblFirstName.ResourceKey = null;
            this.lblFirstName.ResourceModuleKey = "FirstName, TinyERP.ERP";
            this.lblFirstName.Size = new System.Drawing.Size(67, 20);
            this.lblFirstName.TabIndex = 0;
            this.lblFirstName.Text = "First name";
            this.lblFirstName.Values.ExtraText = "";
            this.lblFirstName.Values.Image = null;
            this.lblFirstName.Values.Text = "First name";
            // 
            // txtFirstName
            // 
            this.txtFirstName.Location = new System.Drawing.Point(126, 16);
            this.txtFirstName.Name = "txtFirstName";
            this.txtFirstName.Size = new System.Drawing.Size(156, 20);
            this.txtFirstName.TabIndex = 1;
            // 
            // lblLastName
            // 
            this.lblLastName.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblLastName.Location = new System.Drawing.Point(449, 16);
            this.lblLastName.Name = "lblLastName";
            this.lblLastName.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblLastName.ResourceKey = null;
            this.lblLastName.ResourceModuleKey = "LastName, TinyERP.ERP";
            this.lblLastName.Size = new System.Drawing.Size(66, 20);
            this.lblLastName.TabIndex = 0;
            this.lblLastName.Text = "Last name";
            this.lblLastName.Values.ExtraText = "";
            this.lblLastName.Values.Image = null;
            this.lblLastName.Values.Text = "Last name";
            // 
            // txtLastName
            // 
            this.txtLastName.Location = new System.Drawing.Point(550, 16);
            this.txtLastName.Name = "txtLastName";
            this.txtLastName.Size = new System.Drawing.Size(266, 20);
            this.txtLastName.TabIndex = 2;
            // 
            // lblTitle
            // 
            this.lblTitle.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblTitle.Location = new System.Drawing.Point(9, 41);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblTitle.ResourceKey = null;
            this.lblTitle.ResourceModuleKey = "Title, TinyERP.ERP";
            this.lblTitle.Size = new System.Drawing.Size(34, 20);
            this.lblTitle.TabIndex = 0;
            this.lblTitle.Text = "Title";
            this.lblTitle.Values.ExtraText = "";
            this.lblTitle.Values.Image = null;
            this.lblTitle.Values.Text = "Title";
            // 
            // txtTitle
            // 
            this.txtTitle.Location = new System.Drawing.Point(126, 42);
            this.txtTitle.Name = "txtTitle";
            this.txtTitle.Size = new System.Drawing.Size(156, 20);
            this.txtTitle.TabIndex = 3;
            // 
            // lblDescription
            // 
            this.lblDescription.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblDescription.Location = new System.Drawing.Point(9, 337);
            this.lblDescription.Name = "lblDescription";
            this.lblDescription.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblDescription.ResourceKey = null;
            this.lblDescription.ResourceModuleKey = "Note, TinyERP.ERP";
            this.lblDescription.Size = new System.Drawing.Size(38, 20);
            this.lblDescription.TabIndex = 0;
            this.lblDescription.Text = "Note";
            this.lblDescription.Values.ExtraText = "";
            this.lblDescription.Values.Image = null;
            this.lblDescription.Values.Text = "Note";
            // 
            // txtDescription
            // 
            this.txtDescription.Location = new System.Drawing.Point(9, 363);
            this.txtDescription.Multiline = true;
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new System.Drawing.Size(710, 54);
            this.txtDescription.TabIndex = 12;
            // 
            // lblPhoneNumber
            // 
            this.lblPhoneNumber.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblPhoneNumber.Location = new System.Drawing.Point(9, 124);
            this.lblPhoneNumber.Name = "lblPhoneNumber";
            this.lblPhoneNumber.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblPhoneNumber.ResourceKey = null;
            this.lblPhoneNumber.ResourceModuleKey = "PhoneNumber, TinyERP.ERP";
            this.lblPhoneNumber.Size = new System.Drawing.Size(91, 20);
            this.lblPhoneNumber.TabIndex = 0;
            this.lblPhoneNumber.Text = "Phone number";
            this.lblPhoneNumber.Values.ExtraText = "";
            this.lblPhoneNumber.Values.Image = null;
            this.lblPhoneNumber.Values.Text = "Phone number";
            // 
            // lblWebSite
            // 
            this.lblWebSite.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblWebSite.Location = new System.Drawing.Point(9, 67);
            this.lblWebSite.Name = "lblWebSite";
            this.lblWebSite.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblWebSite.ResourceKey = null;
            this.lblWebSite.ResourceModuleKey = "WebSite, TinyERP.ERP";
            this.lblWebSite.Size = new System.Drawing.Size(58, 20);
            this.lblWebSite.TabIndex = 0;
            this.lblWebSite.Text = "Web site";
            this.lblWebSite.Values.ExtraText = "";
            this.lblWebSite.Values.Image = null;
            this.lblWebSite.Values.Text = "Web site";
            // 
            // txtWebSite
            // 
            this.txtWebSite.Location = new System.Drawing.Point(126, 68);
            this.txtWebSite.Name = "txtWebSite";
            this.txtWebSite.Size = new System.Drawing.Size(289, 20);
            this.txtWebSite.TabIndex = 5;
            // 
            // lblIM
            // 
            this.lblIM.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblIM.Location = new System.Drawing.Point(449, 124);
            this.lblIM.Name = "lblIM";
            this.lblIM.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblIM.ResourceKey = null;
            this.lblIM.ResourceModuleKey = "IM, TinyERP.ERP";
            this.lblIM.Size = new System.Drawing.Size(25, 20);
            this.lblIM.TabIndex = 0;
            this.lblIM.Text = "IM";
            this.lblIM.Values.ExtraText = "";
            this.lblIM.Values.Image = null;
            this.lblIM.Values.Text = "IM";
            // 
            // lblFax
            // 
            this.lblFax.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblFax.Location = new System.Drawing.Point(449, 41);
            this.lblFax.Name = "lblFax";
            this.lblFax.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblFax.ResourceKey = null;
            this.lblFax.ResourceModuleKey = "Fax, TinyERP.ERP";
            this.lblFax.Size = new System.Drawing.Size(28, 20);
            this.lblFax.TabIndex = 0;
            this.lblFax.Text = "Fax";
            this.lblFax.Values.ExtraText = "";
            this.lblFax.Values.Image = null;
            this.lblFax.Values.Text = "Fax";
            // 
            // txtFax
            // 
            this.txtFax.Location = new System.Drawing.Point(550, 42);
            this.txtFax.Name = "txtFax";
            this.txtFax.Size = new System.Drawing.Size(266, 20);
            this.txtFax.TabIndex = 4;
            // 
            // lblCustomerAddressList
            // 
            this.lblCustomerAddressList.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblCustomerAddressList.Location = new System.Drawing.Point(9, 232);
            this.lblCustomerAddressList.Name = "lblCustomerAddressList";
            this.lblCustomerAddressList.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblCustomerAddressList.ResourceKey = null;
            this.lblCustomerAddressList.ResourceModuleKey = "Address, TinyERP.ERP";
            this.lblCustomerAddressList.Size = new System.Drawing.Size(109, 20);
            this.lblCustomerAddressList.TabIndex = 0;
            this.lblCustomerAddressList.Text = "Customer address";
            this.lblCustomerAddressList.Values.ExtraText = "";
            this.lblCustomerAddressList.Values.Image = null;
            this.lblCustomerAddressList.Values.Text = "Customer address";
            // 
            // lblCustomerType
            // 
            this.lblCustomerType.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblCustomerType.Location = new System.Drawing.Point(449, 96);
            this.lblCustomerType.Name = "lblCustomerType";
            this.lblCustomerType.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblCustomerType.ResourceKey = null;
            this.lblCustomerType.ResourceModuleKey = "CustomerType, TinyERP.ERP";
            this.lblCustomerType.Size = new System.Drawing.Size(91, 20);
            this.lblCustomerType.TabIndex = 0;
            this.lblCustomerType.Text = "Customer type";
            this.lblCustomerType.Values.ExtraText = "";
            this.lblCustomerType.Values.Image = null;
            this.lblCustomerType.Values.Text = "Customer type";
            // 
            // cboCustomerType
            // 
            this.cboCustomerType.DropBackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.ControlClient;
            this.cboCustomerType.DropButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.InputControl;
            this.cboCustomerType.DropDownWidth = 164;
            this.cboCustomerType.InputControlStyle = ComponentFactory.Krypton.Toolkit.InputControlStyle.Standalone;
            this.cboCustomerType.ItemStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.ListItem;
            this.cboCustomerType.Location = new System.Drawing.Point(550, 95);
            this.cboCustomerType.Name = "cboCustomerType";
            this.cboCustomerType.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.cboCustomerType.Size = new System.Drawing.Size(164, 21);
            this.cboCustomerType.TabIndex = 8;
            // 
            // lblEmail
            // 
            this.lblEmail.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblEmail.Location = new System.Drawing.Point(9, 96);
            this.lblEmail.Name = "lblEmail";
            this.lblEmail.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblEmail.ResourceKey = null;
            this.lblEmail.ResourceModuleKey = "Email, TinyERP.ERP";
            this.lblEmail.Size = new System.Drawing.Size(40, 20);
            this.lblEmail.TabIndex = 13;
            this.lblEmail.Text = "Email";
            this.lblEmail.Values.ExtraText = "";
            this.lblEmail.Values.Image = null;
            this.lblEmail.Values.Text = "Email";
            // 
            // txtEmail
            // 
            this.txtEmail.Location = new System.Drawing.Point(126, 96);
            this.txtEmail.Name = "txtEmail";
            this.txtEmail.Size = new System.Drawing.Size(289, 20);
            this.txtEmail.TabIndex = 7;
            // 
            // lblBirthdate
            // 
            this.lblBirthdate.LabelStyle = ComponentFactory.Krypton.Toolkit.LabelStyle.NormalControl;
            this.lblBirthdate.Location = new System.Drawing.Point(449, 68);
            this.lblBirthdate.Name = "lblBirthdate";
            this.lblBirthdate.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.lblBirthdate.ResourceKey = null;
            this.lblBirthdate.ResourceModuleKey = "BirthDate, TinyERP.ERP";
            this.lblBirthdate.Size = new System.Drawing.Size(60, 20);
            this.lblBirthdate.TabIndex = 15;
            this.lblBirthdate.Text = "Birthdate";
            this.lblBirthdate.Values.ExtraText = "";
            this.lblBirthdate.Values.Image = null;
            this.lblBirthdate.Values.Text = "Birthdate";
            // 
            // txtBirthDate
            // 
            this.txtBirthDate.Culture = new System.Globalization.CultureInfo("en-US");
            this.txtBirthDate.DateFormat = null;
            this.txtBirthDate.InputControlStyle = ComponentFactory.Krypton.Toolkit.InputControlStyle.Standalone;
            this.txtBirthDate.Location = new System.Drawing.Point(550, 68);
            this.txtBirthDate.Mask = "00/00/0000";
            this.txtBirthDate.Name = "txtBirthDate";
            this.txtBirthDate.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.txtBirthDate.Size = new System.Drawing.Size(164, 20);
            this.txtBirthDate.TabIndex = 6;
            this.txtBirthDate.Text = "01/01/1970";
            this.txtBirthDate.Value = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
            // 
            // btnRemovePhone
            // 
            this.btnRemovePhone.AutoSize = true;
            this.btnRemovePhone.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnRemovePhone.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnRemovePhone.Image = ((System.Drawing.Image)(resources.GetObject("btnRemovePhone.Image")));
            this.btnRemovePhone.Location = new System.Drawing.Point(405, 183);
            this.btnRemovePhone.Name = "btnRemovePhone";
            this.btnRemovePhone.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnRemovePhone.ResourceKey = null;
            this.btnRemovePhone.ResourceModuleKey = null;
            this.btnRemovePhone.Size = new System.Drawing.Size(22, 22);
            this.btnRemovePhone.TabIndex = 18;
            this.btnRemovePhone.Values.ExtraText = "";
            this.btnRemovePhone.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnRemovePhone.Values.Image")));
            this.btnRemovePhone.Values.ImageStates.ImageCheckedNormal = null;
            this.btnRemovePhone.Values.ImageStates.ImageCheckedPressed = null;
            this.btnRemovePhone.Values.ImageStates.ImageCheckedTracking = null;
            this.btnRemovePhone.Values.Text = "";
            // 
            // btnAddIM
            // 
            this.btnAddIM.AutoSize = true;
            this.btnAddIM.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnAddIM.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnAddIM.Image = ((System.Drawing.Image)(resources.GetObject("btnAddIM.Image")));
            this.btnAddIM.Location = new System.Drawing.Point(821, 150);
            this.btnAddIM.Name = "btnAddIM";
            this.btnAddIM.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnAddIM.ResourceKey = null;
            this.btnAddIM.ResourceModuleKey = null;
            this.btnAddIM.Size = new System.Drawing.Size(22, 22);
            this.btnAddIM.TabIndex = 19;
            this.btnAddIM.Values.ExtraText = "";
            this.btnAddIM.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnAddIM.Values.Image")));
            this.btnAddIM.Values.ImageStates.ImageCheckedNormal = null;
            this.btnAddIM.Values.ImageStates.ImageCheckedPressed = null;
            this.btnAddIM.Values.ImageStates.ImageCheckedTracking = null;
            this.btnAddIM.Values.Text = "";
            // 
            // btnRemoveIM
            // 
            this.btnRemoveIM.AutoSize = true;
            this.btnRemoveIM.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnRemoveIM.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnRemoveIM.Image = ((System.Drawing.Image)(resources.GetObject("btnRemoveIM.Image")));
            this.btnRemoveIM.Location = new System.Drawing.Point(821, 183);
            this.btnRemoveIM.Name = "btnRemoveIM";
            this.btnRemoveIM.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnRemoveIM.ResourceKey = null;
            this.btnRemoveIM.ResourceModuleKey = null;
            this.btnRemoveIM.Size = new System.Drawing.Size(22, 22);
            this.btnRemoveIM.TabIndex = 20;
            this.btnRemoveIM.Values.ExtraText = "";
            this.btnRemoveIM.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnRemoveIM.Values.Image")));
            this.btnRemoveIM.Values.ImageStates.ImageCheckedNormal = null;
            this.btnRemoveIM.Values.ImageStates.ImageCheckedPressed = null;
            this.btnRemoveIM.Values.ImageStates.ImageCheckedTracking = null;
            this.btnRemoveIM.Values.Text = "";
            // 
            // btnAddAddress
            // 
            this.btnAddAddress.AutoSize = true;
            this.btnAddAddress.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnAddAddress.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnAddAddress.Image = ((System.Drawing.Image)(resources.GetObject("btnAddAddress.Image")));
            this.btnAddAddress.Location = new System.Drawing.Point(725, 257);
            this.btnAddAddress.Name = "btnAddAddress";
            this.btnAddAddress.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnAddAddress.ResourceKey = null;
            this.btnAddAddress.ResourceModuleKey = null;
            this.btnAddAddress.Size = new System.Drawing.Size(22, 22);
            this.btnAddAddress.TabIndex = 21;
            this.btnAddAddress.Values.ExtraText = "";
            this.btnAddAddress.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnAddAddress.Values.Image")));
            this.btnAddAddress.Values.ImageStates.ImageCheckedNormal = null;
            this.btnAddAddress.Values.ImageStates.ImageCheckedPressed = null;
            this.btnAddAddress.Values.ImageStates.ImageCheckedTracking = null;
            this.btnAddAddress.Values.Text = "";
            // 
            // btnRemoveAddress
            // 
            this.btnRemoveAddress.AutoSize = true;
            this.btnRemoveAddress.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnRemoveAddress.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnRemoveAddress.Image = ((System.Drawing.Image)(resources.GetObject("btnRemoveAddress.Image")));
            this.btnRemoveAddress.Location = new System.Drawing.Point(725, 285);
            this.btnRemoveAddress.Name = "btnRemoveAddress";
            this.btnRemoveAddress.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnRemoveAddress.ResourceKey = null;
            this.btnRemoveAddress.ResourceModuleKey = null;
            this.btnRemoveAddress.Size = new System.Drawing.Size(22, 22);
            this.btnRemoveAddress.TabIndex = 22;
            this.btnRemoveAddress.Values.ExtraText = "";
            this.btnRemoveAddress.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnRemoveAddress.Values.Image")));
            this.btnRemoveAddress.Values.ImageStates.ImageCheckedNormal = null;
            this.btnRemoveAddress.Values.ImageStates.ImageCheckedPressed = null;
            this.btnRemoveAddress.Values.ImageStates.ImageCheckedTracking = null;
            this.btnRemoveAddress.Values.Text = "";
            // 
            // btnAddPhone
            // 
            this.btnAddPhone.AutoSize = true;
            this.btnAddPhone.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btnAddPhone.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.Standalone;
            this.btnAddPhone.Image = ((System.Drawing.Image)(resources.GetObject("btnAddPhone.Image")));
            this.btnAddPhone.Location = new System.Drawing.Point(405, 155);
            this.btnAddPhone.Name = "btnAddPhone";
            this.btnAddPhone.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            this.btnAddPhone.ResourceKey = null;
            this.btnAddPhone.ResourceModuleKey = null;
            this.btnAddPhone.Size = new System.Drawing.Size(22, 22);
            this.btnAddPhone.TabIndex = 23;
            this.btnAddPhone.Values.ExtraText = "";
            this.btnAddPhone.Values.Image = ((System.Drawing.Image)(resources.GetObject("btnAddPhone.Values.Image")));
            this.btnAddPhone.Values.ImageStates.ImageCheckedNormal = null;
            this.btnAddPhone.Values.ImageStates.ImageCheckedPressed = null;
            this.btnAddPhone.Values.ImageStates.ImageCheckedTracking = null;
            this.btnAddPhone.Values.Text = "";
            // 
            // dataGridViewTextBoxColumn1
            // 
            this.dataGridViewTextBoxColumn1.DataPropertyName = "Account";
            dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle9;
            this.dataGridViewTextBoxColumn1.FillWeight = 138.0928F;
            this.dataGridViewTextBoxColumn1.HeaderText = "Account";
            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            // 
            // dataGridViewComboBoxColumn1
            // 
            this.dataGridViewComboBoxColumn1.DataPropertyName = "OnlineService";
            this.dataGridViewComboBoxColumn1.FillWeight = 96.42347F;
            this.dataGridViewComboBoxColumn1.HeaderText = "Online service";
            this.dataGridViewComboBoxColumn1.Items.AddRange(new object[] {
            "yahoo",
            "skype",
            "msn",
            "googletalk"});
            this.dataGridViewComboBoxColumn1.Name = "dataGridViewComboBoxColumn1";
            // 
            // dataGridViewCheckBoxColumn1
            // 
            this.dataGridViewCheckBoxColumn1.DataPropertyName = "IsPrimaryAccount";
            this.dataGridViewCheckBoxColumn1.FillWeight = 102.7079F;
            this.dataGridViewCheckBoxColumn1.HeaderText = "Primary";
            this.dataGridViewCheckBoxColumn1.Name = "dataGridViewCheckBoxColumn1";
            // 
            // gridAddress
            // 
            dataGridViewCellStyle12.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            gridAddress.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle12;
            gridAddress.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            gridAddress.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllHeaders;
            gridAddress.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colStreetAddress,
            this.colCity,
            this.colCountry,
            this.colIsMainAddress});
            gridAddress.GridStyles.Style = ComponentFactory.Krypton.Toolkit.DataGridViewStyle.Mixed;
            gridAddress.GridStyles.StyleBackground = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridAddress.GridStyles.StyleColumn = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridAddress.GridStyles.StyleDataCells = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridAddress.GridStyles.StyleRow = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridAddress.Location = new System.Drawing.Point(13, 257);
            gridAddress.ModuleAssemblyName = "TinyERP.ERP";
            gridAddress.Name = "gridAddress";
            gridAddress.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            gridAddress.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            gridAddress.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            gridAddress.ShowEditingIcon = false;
            gridAddress.Size = new System.Drawing.Size(706, 74);
            gridAddress.SortKeyMap = ((System.Collections.Hashtable)(resources.GetObject("gridAddress.SortKeyMap")));
            gridAddress.SortOnCurrentPage = false;
            gridAddress.StateCommon.BackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridAddress.TabIndex = 11;
            // 
            // gridPhoneNumber
            // 
            dataGridViewCellStyle10.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            gridPhoneNumber.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle10;
            gridPhoneNumber.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            gridPhoneNumber.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colPhoneNumber,
            this.colPhoneType,
            this.colPhoneNumberType,
            this.colIsPrimaryPhoneNumber});
            gridPhoneNumber.GridStyles.Style = ComponentFactory.Krypton.Toolkit.DataGridViewStyle.Mixed;
            gridPhoneNumber.GridStyles.StyleBackground = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridPhoneNumber.GridStyles.StyleColumn = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridPhoneNumber.GridStyles.StyleDataCells = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridPhoneNumber.GridStyles.StyleRow = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridPhoneNumber.Location = new System.Drawing.Point(11, 150);
            gridPhoneNumber.ModuleAssemblyName = "TinyERP.ERP";
            gridPhoneNumber.Name = "gridPhoneNumber";
            gridPhoneNumber.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            gridPhoneNumber.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            gridPhoneNumber.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            gridPhoneNumber.ShowEditingIcon = false;
            gridPhoneNumber.Size = new System.Drawing.Size(387, 74);
            gridPhoneNumber.SortKeyMap = ((System.Collections.Hashtable)(resources.GetObject("gridPhoneNumber.SortKeyMap")));
            gridPhoneNumber.SortOnCurrentPage = false;
            gridPhoneNumber.StateCommon.BackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridPhoneNumber.TabIndex = 9;
            // 
            // gridIM
            // 
            dataGridViewCellStyle8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            gridIM.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle8;
            gridIM.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            gridIM.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dataGridViewTextBoxColumn1,
            this.dataGridViewComboBoxColumn1,
            this.dataGridViewCheckBoxColumn1});
            gridIM.GridStyles.Style = ComponentFactory.Krypton.Toolkit.DataGridViewStyle.Mixed;
            gridIM.GridStyles.StyleBackground = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridIM.GridStyles.StyleColumn = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridIM.GridStyles.StyleDataCells = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridIM.GridStyles.StyleRow = ComponentFactory.Krypton.Toolkit.GridStyle.Sheet;
            gridIM.Location = new System.Drawing.Point(454, 150);
            gridIM.ModuleAssemblyName = "TinyERP.ERP";
            gridIM.Name = "gridIM";
            gridIM.PaletteMode = ComponentFactory.Krypton.Toolkit.PaletteMode.Global;
            gridIM.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            gridIM.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            gridIM.ShowEditingIcon = false;
            gridIM.Size = new System.Drawing.Size(340, 74);
            gridIM.SortKeyMap = ((System.Collections.Hashtable)(resources.GetObject("gridIM.SortKeyMap")));
            gridIM.SortOnCurrentPage = false;
            gridIM.StateCommon.BackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridDataCellSheet;
            gridIM.TabIndex = 10;
            // 
            // CustomerEditInfoForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(861, 458);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "CustomerEditInfoForm";
            this.Text = "Customer information";
            this.Load += new System.EventHandler(this.CustomerEditInfoForm_Load);
            this.contentPanel.ResumeLayout(false);
            this.contentPanel.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.cboCustomerType)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(gridAddress)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(gridPhoneNumber)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(gridIM)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion


		public CustomerEditInfoForm() : base()
		{
			InitializeComponent();
            this.btnAddAddress.Click += new EventHandler(OnAddAddressClick);
            this.btnRemoveAddress.Click += new EventHandler(OnRemoveAddressClick);
            this.btnAddIM.Click += new EventHandler(OnAddIMClick);
            this.btnRemoveIM.Click += new EventHandler(OnRemoveIMClick);
            this.btnAddPhone.Click += new EventHandler(OnAddPhoneClick);
            this.btnRemovePhone.Click += new EventHandler(OnRemovePhoneClick);
		}

        void OnRemovePhoneClick(object sender, EventArgs e)
        {
            if (gridPhoneNumber.SelectedRows.Count > 0)
            {
                DataGridViewRow selectedRow = gridPhoneNumber.SelectedRows[0];
                PhoneNumberDTO selectedPhone =  (PhoneNumberDTO) selectedRow.DataBoundItem;
                this.customer.PhoneList.Remove(selectedPhone);
                gridPhoneNumber.DataSource = null;
                gridPhoneNumber.DataSource = this.customer.PhoneList;
                gridPhoneNumber.Update();
            }
        }

        void OnAddPhoneClick(object sender, EventArgs e)
        {
            this.customer.PhoneList.Add(new PhoneNumberDTO());
            gridPhoneNumber.DataSource = null;
            gridPhoneNumber.DataSource = this.customer.PhoneList;
            gridPhoneNumber.Update();
        }

        void OnRemoveIMClick(object sender, EventArgs e)
        {
            if (gridIM.SelectedRows.Count > 0)
            {
                DataGridViewRow selectedRow = gridIM.SelectedRows[0];
                IMContactDTO selectedIM = (IMContactDTO)selectedRow.DataBoundItem;
                this.customer.IMContactList.Remove(selectedIM);
                gridIM.DataSource = null;
                gridIM.DataSource = this.customer.IMContactList;
                gridIM.Update();
            }
        }

        void OnAddIMClick(object sender, EventArgs e)
        {
            this.customer.IMContactList.Add(new IMContactDTO());
            gridIM.DataSource = null;
            gridIM.DataSource = this.customer.IMContactList;
            gridIM.Update();
        }

        void OnRemoveAddressClick(object sender, EventArgs e)
        {
            if (gridAddress.SelectedRows.Count > 0)
            {
                DataGridViewRow selectedAddress = gridAddress.SelectedRows[0];
                AddressDTO selectedIM = (AddressDTO)selectedAddress.DataBoundItem;
                this.customer.ContactAddressList.Remove(selectedIM);
                gridAddress.DataSource = null;
                gridAddress.DataSource = this.customer.ContactAddressList;
                gridAddress.Update();
            }
        }

        void OnAddAddressClick(object sender, EventArgs e)
        {
            this.customer.ContactAddressList.Add(new AddressDTO());
            gridAddress.DataSource = null;
            gridAddress.DataSource = this.customer.ContactAddressList;
            gridAddress.Update();
        }
		
		protected override void AddValidationRules() 
		{
			base.AddValidationRules();
            validator.AddValidationRule(new RequiredFieldRule(txtFirstName, 
                ModuleResourceManager.GetInstance().GetStringFromModuleResourceKey("FirstName, TinyERP.ERP")));
            validator.AddValidationRule(new RequiredFieldRule(txtLastName,
                ModuleResourceManager.GetInstance().GetStringFromModuleResourceKey("LastName, TinyERP.ERP")));

		}
		
		
		
		private void PrepareData() 
		{
		}
		
		protected override void LoadEntityInfo() 
		{
			PrepareData();
		    if(customer==null) 
		    {
				customer = new CustomerDTO();
                customer.PhoneList = new List<PhoneNumberDTO>();
                customer.IMContactList = new List<IMContactDTO>();
                customer.ContactAddressList = new List<AddressDTO>();
		    }
            if (customer.PhoneList.Count == 0)
            {
                PhoneNumberDTO emptyPhoneNumber = new PhoneNumberDTO();
                customer.PhoneList.Add(emptyPhoneNumber);
            }

            if (customer.IMContactList.Count == 0)
            {
                IMContactDTO emptyIM = new IMContactDTO();
                customer.IMContactList.Add(emptyIM);
            }

            if (customer.ContactAddressList.Count == 0)
            {
                AddressDTO emptyAddress = new AddressDTO();
                customer.ContactAddressList.Add(emptyAddress);
            }
			txtFirstName.Text = customer.FirstName;
			txtLastName.Text = customer.LastName;
			txtTitle.Text = customer.Title;
			txtDescription.Text = customer.Description;
			
			txtWebSite.Text = customer.WebSite;
			
			txtFax.Text = customer.Fax;
            this.gridPhoneNumber.DataSource = customer.PhoneList;
            this.gridAddress.DataSource = customer.ContactAddressList;
            this.gridIM.DataSource = customer.IMContactList;
			deleteButton.Visible = (customer.ID != 0) ;
		}
		
		protected override bool ValidateInputData() 
		{
			if(!base.ValidateInputData()) 
			{
				return false;
			}
			//TODO: add your business validation here
			return true;
		}
		
		private bool UpdateEntityInfoFromInput() 
		{
			if(!ValidateInputData()) 
			{
				return false;
			}
			customer.FirstName = txtFirstName.Text;
			customer.LastName = txtLastName.Text;
			customer.Title = txtTitle.Text;
			customer.Description = txtDescription.Text;
			customer.WebSite = txtWebSite.Text;
			customer.Fax = txtFax.Text;
			
			return true;
		}
        private AddressDTO FindEmptyAddress()
        {
            foreach (AddressDTO item in customer.ContactAddressList)
            {
                if (string.IsNullOrEmpty(item.StreetAddress))
                {
                    return item;
                }
            }
            return null;
        }

        private IMContactDTO FindEmptyIM()
        {
            foreach (IMContactDTO item in customer.IMContactList)
            {
                if (string.IsNullOrEmpty(item.Account) || string.IsNullOrEmpty(item.OnlineService))
                {
                    return item;
                }
            }
            return null;
        }

        private PhoneNumberDTO FindEmptyPhoneNumber()
        {
            foreach (PhoneNumberDTO item in customer.PhoneList)
            {
                if (string.IsNullOrEmpty(item.PhoneNumber))
                {
                    return item;
                }
            }
            return null;
        }

        private void ClearAllEmptyIM()
        {
            IMContactDTO emptyContact = null;
            do {
                emptyContact = FindEmptyIM();
                customer.IMContactList.Remove(emptyContact);
            } while(emptyContact!=null);
        }

        private void ClearAllEmptyPhone()
        {
            PhoneNumberDTO emptyPhone = null;
            do
            {
                emptyPhone = FindEmptyPhoneNumber();
                customer.PhoneList.Remove(emptyPhone);
            } while (emptyPhone != null);
        }

        private void ClearAllEmptyAddess()
        {
            AddressDTO emptyAddress = null;
            do
            {
                emptyAddress = FindEmptyAddress();
                customer.ContactAddressList.Remove(emptyAddress);
            } while (emptyAddress != null);
        }

        public override void OnSave()
        {
			if(!UpdateEntityInfoFromInput()) 
			{
				return;
			}
			try {
                ClearAllEmptyAddess();
                ClearAllEmptyIM();
                ClearAllEmptyPhone();
				if(customer.ID==0) 
				{
					CustomerService.SaveCustomer(customer);
				}
				else 
				{
					CustomerService.UpdateCustomer(customer);
				}
				MessageBox.Show(CommonMessage.GetSaveSuccessMessage(GetEntityResourceKey()));
                InvokeOnNeedReloadData();
                InvokeCloseDialog();
			} 
			catch(Exception ex) 
			{
                logger.Error(ex);			
				MessageBox.Show(CommonMessage.GetCanNotSaveError(GetEntityResourceKey()));
			}
        }

        public override void OnDelete()
        {
			try 
			{
                if (ConfirmDelete() == DialogResult.OK)
                {
					CustomerService.DeleteCustomerByID(customer.ID);			
					MessageBox.Show(CommonMessage.GetDeleteSuccessMessage(GetEntityResourceKey()));
                    InvokeOnNeedReloadData();
                    InvokeCloseDialog();
				}
			}
			catch(Exception ex) 
			{
                logger.Error(ex);			
				MessageBox.Show(CommonMessage.GetCanNotDeleteError(GetEntityResourceKey()));
			}
        }

        
        public override string GetHeaderText()
        {
            return ModuleResourceManager.GetInstance().GetStringFromModuleResourceKey("CustomerEditForm, TinyERP.Core");
        }

        private string GetEntityResourceKey()
        {
            return ModuleResourceManager.GetInstance().GetStringFromModuleResourceKey("Customer, TinyERP.Core");
        }

        private DialogResult ConfirmDelete()
        {
            return MessageBox.Show(CommonMessage.GetDeleteConfirmMessage(GetEntityResourceKey()),
                CommonMessage.GetConfirmationText(), MessageBoxButtons.OKCancel);
        }

        private void CustomerEditInfoForm_Load(object sender, EventArgs e)
        {

        }

	}
}

